#include "../source/vlib.h"
#include <stdio.h>

static void test_create(void)
{
	set_t set = set(int);
	_set(set);
}

static void test_at(void)
{
	set_t set = set(int);
	
	set_insert(set, 0, la(int, 0));
	set_insert(set, 10, la(int, 1024));
	set_insert(set, -1, la(int, -1000));
	set_insert(set, 100, la(int, 100));
	
	printf("set[0] = %d\r\n", set_at(set, int, 0));
	printf("set[10] = %d\r\n", set_at(set, int, 10));
	printf("set[-1] = %d\r\n", set_at(set, int, -1));
	printf("set[100] = %d\r\n", set_at(set, int, 100));
	printf("set[2] = %d\r\n", set_at(set, int, 2)); // A nonexistent index

	_set(set);
}

static void test_find(void)
{
	set_t set = set(int);
	
	set_insert(set, 0, la(int, 0));
	set_insert(set, 10, la(int, 1024));
	set_insert(set, -1, la(int, -1000));
	set_insert(set, 100, la(int, 100));
	
	printf("find %d\r\n", set_find(set, 10));
	printf("find %d\r\n", set_find(set, 2));

	_set(set);
}

static void test_erase(void)
{
	set_t set = set(int);
	
	set_insert(set, 0, la(int, 0));
	set_insert(set, 10, la(int, 1024));
	set_insert(set, -1, la(int, -1000));
	set_insert(set, 100, la(int, 100));
	
	printf("find %d\r\n", set_find(set, 10));
	set_erase(set, 10);
	printf("find %d\r\n", set_find(set, 10));

	_set(set);
}

static void set_show(int index, void* data)
{
    printf("set[%d] = %d\r\n", index, *(int *)data);
}

static void test_traverse(void)
{
    set_t set = set(int);
	
    set_insert(set, 0, la(int, 0));
	set_insert(set, 10, la(int, 1024));
	set_insert(set, -1, la(int, -1000));
	set_insert(set, 100, la(int, 100));
	set_insert(set, 100, la(int, 1)); // Repeat insertion

    set_traverse(set, set_show);

    _set(set);
}

void test_set(void)
{
    // test_create();
	// test_at();
	// test_find();
	// test_erase();
	test_traverse();
}